var mongoose = require("mongoose");

var SessionSchema = new mongoose.Schema({   // Schema
    "kid" : Number,
    "name": String,
    "students": [Number],   //数组存放的是学生的sid
});
SessionSchema.index({"kid": 1});     // 索引

SessionSchema.statics.AddStudents = function(kidarray,sid,callback){
    for(var i = 0;i < kidarray.length;i++){
        Session.update({"kid":kidarray[i]},{$push:{"students":sid}},function(){
            console.log("课程添加报名学生成功");
        });
    }
}

var Session = mongoose.model("Session",SessionSchema);   // model
module.exports = Session;